package cn.com.twoke.game.client.games.tic_tac_toe.constants;

import cn.com.twoke.game.client.games.framework.component.LogicComponent;
import cn.com.twoke.game.client.games.framework.component.RenderComponent;

import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;

public interface TicTacToeChess extends RenderComponent, LogicComponent,TicTacToeGameConstant {

    Color CIRCLE_COLOR = Color.BLUE;
    Color CROSS_COLOR = Color.RED;

    int CIRCLE_RADIUS = 80;
    int CROSS_PADDING = 10;
    int CROSS_WIDTH = CELL_WIDTH / 2 - CROSS_PADDING;


    enum Type {
        NONE(null, 0) {
            @Override
            public void render(Graphics2D g, int x, int y) {}
        } ,
        CIRCLE(CIRCLE_COLOR, 1) {
            @Override
            public void render(Graphics2D g, int x, int y) {
                Color oldColor = g.getColor();
                g.setColor(getColor());
                g.setStroke(new BasicStroke(10));
                g.drawOval(TicTacToeGameConstant.cellX(x) - CIRCLE_RADIUS  + CELL_WIDTH  / 2,
                        TicTacToeGameConstant.cellY(y) - CIRCLE_RADIUS + CELL_WIDTH  / 2, 2 * CIRCLE_RADIUS, 2 * CIRCLE_RADIUS);
                g.setColor(oldColor);
            }
        },
        CROSS(CROSS_COLOR, -1) {
            @Override
            public void render(Graphics2D g, int x, int y) {
                Color oldColor = g.getColor();
                AffineTransform oldTransform = g.getTransform();
                g.setColor(getColor());
                g.setStroke(new BasicStroke(10));
                g.rotate(Math.toRadians(45), TicTacToeGameConstant.cellX(x) + CELL_WIDTH / 2, TicTacToeGameConstant.cellY(y) + CELL_WIDTH / 2);
                Line2D.Double line = new Line2D.Double(
                        TicTacToeGameConstant.cellX(x) + CROSS_PADDING , TicTacToeGameConstant.cellY(y) + CELL_WIDTH / 2,
                        TicTacToeGameConstant.cellX(x) + CELL_WIDTH  - CROSS_PADDING, TicTacToeGameConstant.cellY(y) + CELL_WIDTH / 2);
                g.draw(line);
                line = new Line2D.Double(
                        TicTacToeGameConstant.cellX(x) + CELL_WIDTH / 2, TicTacToeGameConstant.cellY(y) + CROSS_PADDING,
                        TicTacToeGameConstant.cellX(x) + CELL_WIDTH / 2, TicTacToeGameConstant.cellY(y) + CELL_WIDTH - CROSS_PADDING);
                g.draw(line);
                g.setTransform(oldTransform);
                g.setColor(oldColor);
            }
        };

        private final Color color;
        private final int code;

        Type(Color color, int code) {
            this.color = color;
            this.code = code;
        }


        public int getCode() {
            return code;
        }

        public Color getColor() {
            return color;
        }

        public abstract void render(Graphics2D g, int x, int y);
    }


}
